import cv2 as cv


def open_demo(image):
    gray = cv.cvtColor(image,cv.COLOR_BGR2GRAY)
    ret,binary = cv.threshold(gray,0,255,cv.THRESH_BINARY|cv.THRESH_OTSU)
    kernel = cv.getStructuringElement(cv.MORPH_RECT,(3,3))
    dst = cv.morphologyEx(binary,cv.MORPH_OPEN,kernel)
    cv.imshow('open_demo',dst)


def close_demo(image):
    gray = cv.cvtColor(image,cv.COLOR_BGR2GRAY)
    ret,binary = cv.threshold(gray,0,255,cv.THRESH_BINARY|cv.THRESH_OTSU)
    kernel = cv.getStructuringElement(cv.MORPH_RECT,(3,3))
    dst = cv.morphologyEx(binary,cv.MORPH_OPEN,kernel)
    cv.imshow('close_demo',dst)


src = cv.imread('notes.png',1)
cv.namedWindow('demo',cv.WINDOW_AUTOSIZE)
cv.imshow('demo',src)
open_demo(src)
cv.waitKey(0)
cv.destroyAllWindows()